#ifndef GL_GRAPHICS_DEVICE
#define GL_GRAPHICS_DEVICE
#include "Interfaces/IGraphicsDevice.h"
#include "OglRenderContext.h"
using namespace gname;
namespace gengine
{
	namespace kernel
	{
		class GlGraphicsDevice:public IGraphicsDevice
		{
		public:
			GlGraphicsDevice	        (IGraphicsDevice::DeviceParameters &dp);
			virtual ~GlGraphicsDevice	();

			IVertexBuffer     *CreateVertexBuffer( UINT size,int typeSize);
		    IIndexBuffer      *CreateIndexBuffer( )          ;
		    VertexDeclaration *CreateVertexDeclaration( )    ;
			ITexture          *CreateTexture(  Vector2D &size, TextureCreationType, TextureInternalFormat, int miplevels=0 );
		    IShaderProgram    *CreateShader(ShaderProgramType type );
			
			void		SetVertexDeclaration( VertexDeclaration* );
		    void		SetSampler( Sampler* );
			void        SetShader(IShaderProgram*,bool use = true);
			void		SetTexture( ITexture*);
		    void		SetVertexBuffer( IVertexBuffer* );
		    void		SetIndexBuffer( IIndexBuffer* )  ;
		
		    void		SetRenderTarget( ITexture* );
			
			Camera *	  GetCamera		() const ;
			void          SetCamera     (Camera *cam);
			
			const char *	GetVendor		() const ;
	        const char *	GetRenderer		() const ;
	        const char *	GetVersion		() const ;

			void SetClearFlags(ClearType *type);
			
			void		BeginScene ();
		    void		EndScene   ();
			void		Draw       (IIndexBuffer*buf);
		    void		SwapBuffers();
		    void		Clear      ();
			void        ClearBuffers(ClearType type);
            bool        GlInit     ();
			
			
            
			
			Window	*	GetWindow		() const ;
			bool        SetWindow       (string wndName);
			Window	*	ECreateWindow	( const char* wndTitle, const char* wndClassName, IGraphicsDevice::DeviceParameters&dp);
			void        DeleteWindow    (const string& wndName) ;
			void        Resize(int w , int h);
			
		
	     
			RenderState	    *		GetRendererState	() const ;
            RenderContext	*		GetRendererContext	() const ;
			
	       	void	SetRendererContext	( RenderContext * context);
	        void	GetDisplayModes			();
			
			
		private:
			
			
			 Camera                 * camera;
			 
			 Window					* currentWindow;
	         OGLRenderContext	    * currentContext;

			  Window					* resourceWindow;
			
	          OGLRenderContext	     * resourceContext;
			 
			 static int glMinorVersion;
			 static int glMadjorVersion;
			
			 HINSTANCE                                       hInstance;
			 vector<IGraphicsDevice::DeviceParameters>		 videoModes;
			 IGraphicsDevice::DeviceParameters				 currentVideoMode;
			 map<string,Window*>	                         windows;
			 map<string,OGLRenderContext*>	                 GLContexts;
		     Window	*	AddWindow	( const char* wndTitle, const char* wndClassName, int w,int h, int dpp, int pixelBits,bool isFullS) ;
			 ClearType clearFlags;
		//protected:
			
		};
	}
}

#endif